package game

import (
	"time"
	"math/rand"
	"gitee.com/lwow2025/snake-go/config"
)

// 屏幕左上角为原点
type Point struct {
	X int
	Y int

	PType PointType
	// for show
	Face string
}

func (p *Point) GetFace() string {
	if p.Face != "" {
		return p.Face
	}

	switch p.PType {
	case PointOfSnake:
		p.Face = config.SnakeBody
	case PointOfFood:
		p.Face = randAFood()
	default:
		panic("unknown point type")
	}

	return p.Face
}
func randAFood() string {
	fLen := len(config.Foods)
	rand.Seed(time.Now().UnixNano())
	return config.Foods[rand.Intn(fLen)]
}

func (p *Point) Equal(other *Point) bool {
	return p.X == other.X && p.Y == other.Y
}

func (p *Point) Move(d Direction) *Point {
	switch d {
	case Up:
		return &Point{ X: p.X, Y: p.Y - 1 }
	case Down:
		return &Point{ X: p.X, Y: p.Y + 1 }
	case Left:
		return &Point{ X: p.X - 1, Y: p.Y}
	case Right:
		return &Point{ X: p.X + 1, Y: p.Y}
	default:
		return &Point{ X: p.X, Y: p.Y}
	}
	panic("invalid direction")
}